package com.quxiu.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.quxiu.common.core.utils.DateUtils;
import com.quxiu.system.service.IdService;
import org.springframework.stereotype.Service;
import com.quxiu.system.mapper.BpmProcGroupMapper;
import com.quxiu.system.domain.BpmProcGroup;
import com.quxiu.system.service.IBpmProcGroupService;

import javax.annotation.Resource;

/**
 * 流程分组Service业务层处理
 *
 * @author quxiu
 * @date 2024-06-14
 */
@Service
public class BpmProcGroupServiceImpl implements IBpmProcGroupService {
    @Resource
    private BpmProcGroupMapper bpmProcGroupMapper;
    @Resource
    private IdService idService;

    /**
     * 查询流程分组
     *
     * @param groupId 流程分组主键
     * @return 流程分组
     */
    @Override
    public BpmProcGroup selectBpmProcGroupByGroupId(Long groupId) {
        return bpmProcGroupMapper.selectBpmProcGroupByGroupId(groupId);
    }

    /**
     * 查询流程分组列表
     *
     * @param bpmProcGroup 流程分组
     * @return 流程分组
     */
    @Override
    public List<BpmProcGroup> selectBpmProcGroupList(BpmProcGroup bpmProcGroup) {
        return bpmProcGroupMapper.selectBpmProcGroupList(bpmProcGroup);
    }

    /**
     * 新增流程分组
     *
     * @param bpmProcGroup 流程分组
     * @return 结果
     */
    @Override
    public int insertBpmProcGroup(BpmProcGroup bpmProcGroup) {
        bpmProcGroup.setGroupId(idService.nextId());
        bpmProcGroup.setCreateTime(DateUtils.getNowDate());
        return bpmProcGroupMapper.insertBpmProcGroup(bpmProcGroup);
    }

    /**
     * 修改流程分组
     *
     * @param bpmProcGroup 流程分组
     * @return 结果
     */
    @Override
    public int updateBpmProcGroup(BpmProcGroup bpmProcGroup) {
        bpmProcGroup.setUpdateTime(DateUtils.getNowDate());
        return bpmProcGroupMapper.updateBpmProcGroup(bpmProcGroup);
    }

    /**
     * 批量删除流程分组
     *
     * @param groupIds 需要删除的流程分组主键
     * @return 结果
     */
    @Override
    public int deleteBpmProcGroupByGroupIds(Long[] groupIds) {
        return bpmProcGroupMapper.deleteBpmProcGroupByGroupIds(groupIds);
    }

    /**
     * 删除流程分组信息
     *
     * @param groupId 流程分组主键
     * @return 结果
     */
    @Override
    public int deleteBpmProcGroupByGroupId(Long groupId) {
        return bpmProcGroupMapper.deleteBpmProcGroupByGroupId(groupId);
    }

    @Override
    public Map<Long, String> getGroupMap() {
        List<BpmProcGroup> list = bpmProcGroupMapper.selectBpmProcGroupList(new BpmProcGroup());
        if (list != null) {
            return list.stream().collect(
                    (HashMap::new),
                    (m, v) -> m.put(v.getGroupId(), v.getGroupName()),
                    (m, v) -> {
                    });
        }
        return new HashMap<>();
    }
}
